package com.example.academic_affairs_system.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author hjx
 * @since 2023/02/04 1:54 PM
 */
public class AasClassProvider {
  public String getClassStudentDirectorStatics(@Param("directorId") long directorId) {
    return new SQL() {
      {
        SELECT(
                "ac.id as id",
                "ac.class_code as classCode",
                "ac.name",
                "count(acs.student_id) as `size`")
            .FROM("aas_class ac")
            .LEFT_OUTER_JOIN("aas_class_student acs on ac.id = acs.class_id")
            .WHERE("ac.directors_user_id = #{directorId}")
            .GROUP_BY("ac.id");
      }
    }.toString();
  }

  public String getClassStudentByCoursesId() {
    return new SQL() {
      {
        SELECT("id as classId", "name", "class_code as classCode", "`desc`", "`type`")
            .FROM("from aas_class ac")
            .WHERE(
                "ac.id in (select class_id from aas_class_courses  where acc.courses_id = #{coursesId} acc group by courses_id)")
            .AND()
            .WHERE("ac.enabled = 1");
      }
    }.toString();
  }
}
